package com.financing.service.finance;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.financing.model.finance.TransferLog;
import com.financing.model.system.Logger;
import com.financing.model.user.User;
import com.financing.service.BaseService;
import com.jfinal.plugin.activerecord.Page;

public class TransferService extends BaseService<User>{
	/**
	 * 新增转账记录
	 */
	public void build(User from, User to, double amount, String summary, User operator) {
		if(to!=null && amount>0) {
			TransferLog log = new TransferLog();
			log.setFrom(from.getId());
			log.setFromRealName(from.getRealName());
			log.setTo(to.getId());
			log.setToRealName(to.getRealName());
			log.setCreateTime(new Date());
			log.setSummary(summary);
			log.setAmount(amount);
			log.setOperator(operator.getId());
			log.setOperatorRealName(operator.getRealName());
			log.save();
		}
	}
	
	/**
	 * 分页数据
	 */ 
	public Page<Logger> list(int page, int size, Map<String, String> map) {
		return Logger.me.paginate(page, size, buildSql("logger",Arrays.asList("role", "user_id", "mobile", "create_time", "type"),map));
	}
}
